<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "db_sipemenang";

// Koneksi dan memilih database di server
mysql_connect($server,$username,$password) or die("Failed Conection");
mysql_select_db($database) or die("Cannot Open Database !!!");

//function encrypt password
function encrypt_password($str){
	if (!empty($str)) return md5($str.'selly');
	else return '';
}

function filter($str){
	$blok=array("/","'","\"","%","\\","<",">","(",")","{","}","[","]","+","|","#","&","*","?");
	$str=str_replace($blok,"",$str);
	return $str;
}

function validasi_cari(){
	$field = isset($_GET['field']) ? $_GET['field']:'f'; //$field=block_injection($field,'xss');
	$cari = isset($_GET['cari']) ? $_GET['cari']:''; //$cari=block_injection($cari,'htmlenc');
	$token = isset($_GET['token']) ? $_GET['token']:''; $token=block_injection($token,'xss');
	$token_key = get_token($field,$cari);
	//echo $cari.' - '.$token.' - '.$token_key;
	if(!empty($cari) && $token != $token_key) $cari="";
	return array ($field,$cari,$token_key);
}

function paging($dataPerPage){
	$hal=isset($_GET['page']) ? $_GET['page']:'1';
	if(isset($_GET['page']) && !empty($hal)){$noPage = $hal;} else {$noPage = 1;}	
	$offset = ($noPage - 1) * $dataPerPage;
	return $offset;
}

function echo_paging($jumData,$self,$dataPerPage){
	$hal=isset($_GET['page']) ? $_GET['page']:'';
	if(isset($_GET['page'])){$noPage = $hal;} else {$noPage = 1;}
	echo "<div class='paging'>";
	$jumPage = ceil($jumData/$dataPerPage);
	if ($jumData!=0) echo "page: ";		
	if ($noPage > 1) echo  "<a href='".$self."page=".($noPage-1)."'>&lt; Prev</a>";	 // menampilkan link previous	
	$showPage=0;
	for($page = 1; $page <= $jumPage; $page++){ // memunculkan nomor page dan linknya
		if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage)){   
			if (($showPage == 1) && ($page != 2))  echo "..."; 
			if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
			if ($page == $noPage) echo " <b>".$page."</b>";
			else echo "<a href='".$self."page=".$page."'> ".$page." </a> ";
			$showPage = $page;          
		}
	}				
	if ($noPage < $jumPage) echo "<a href='".$self."page=".($noPage+1)."'>Next &gt;</a>";// menampilkan link next
	echo "</div><div class='clear'></div>";
}

?>